<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of simplecache</title>
  <meta name="keywords" content="simplecache">
  <meta name="description" content="A very simply cache that can be used to store results of computations.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<!-- menu.html matlab -->
<h1>simplecache
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>A very simply cache that can be used to store results of computations.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function varargout = simplecache( op, cache, varargin ) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> A very simply cache that can be used to store results of computations.  

 Can save and retrieve arbitrary values using a vector (includnig char vectors) as a key.
 Especially useful if a function must perform heavy computation but is often called with
 the same inputs (for which it will give the same outputs).  Note that the current
 implementation does a linear search for the key (a more refined implementation would use
 a hash table), so it is not meant for large scale usage.

 To use inside a function, make the cache persistent: 
   persistent cache; if( isempty(cache) ) cache=simplecache('init'); end;
 The following line, when placed inside a function, means the cache will stay in memory
 until the matlab environment changes.  For an example usage see mask_gaussians.

 USAGE:
   %%% initialize a cache:
   cache = simplecache('init');   

   %%% put something in a cache.  Note that key must be a numeric vector.
   %%% if cache already contained an object with the same key that obj is overwritten.
   cache = simplecache( 'put', cache, key, val );

   %%% attempt to get something from cache.  found==1 if obj was found, val is the obj.
   [found,val] = simplecache( 'get', cache, key );

   %%% free key
   [cache,found] = simplecache( 'remove', cache, key );


 EXAMPLE
   cache = simplecache('init');
   hellokey=rand(1,3); worldkey=rand(1,11);
   cache = simplecache( 'put', cache, hellokey, 'hello' );
   cache = simplecache( 'put', cache, worldkey, 'world' );
   [f,v]=simplecache( 'get', cache, hellokey ); disp(v);
   [f,v]=simplecache( 'get', cache, worldkey ); disp(v);

 DATESTAMP
   29-Sep-2005  2:00pm

 See also PERSISTENT, MASK_GAUSSIANS</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="int2str2.html" class="code" title="function nstr = int2str2( n, ndigits )">int2str2</a>	Convert integer to string of given length; improved version of int2str.</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="../images/mask_gaussians.html" class="code" title="function [masks,keeplocs] = mask_gaussians( siz, M, windowwidth, offset, show )">mask_gaussians</a>	Divides a volume into softly overlapping gaussian windows.</li></ul>
<!-- crossreference -->



<hr><address>Generated on Wed 03-May-2006 23:48:50 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2003</address>
</body>
</html>